package com.example.springalibabacloudclient.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.springalibabacloudclient.utils.Results;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import io.swagger.annotations.Api;
import jdk.nashorn.internal.ir.RuntimeNode;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Classname HystrixController
 * @Description TODO
 * @Date 2022/5/14 12:37
 * @Created by XiongXiong
 * @Author: X.I.O
 */
@RestController
@Api(tags = {"熔断服务"})
@RequestMapping("Hystrix")
public class HystrixController {

    /**
     * 熔断 : 127.0.0.1:8012/Hystrix/v1
     * @return
     * @throws Exception
     */
    @GetMapping("v1")
    @HystrixCommand(fallbackMethod = "methodFallback",
            commandProperties=@HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000"))
    public JSONObject v1Controller() throws Exception{
        Thread.sleep(5000);
        return Results.success();
    }

    public String methodFallback(){
        return "服务暂时,出了点问题";
    }

    @GetMapping("v2")
    public JSONObject v2COntroller(){
        return Results.success();
    }


}
